﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace RL
{
    /// <summary>
    /// Логика взаимодействия для wRecalcInsurance.xaml
    /// </summary>
    public partial class wRecalcInsurance : Window
    {
        public wRecalcInsurance()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                routelistEntities rl = new routelistEntities();
                DateTime dtbeg, dtend;
                dtbeg = datePicker1.SelectedDate.HasValue ? datePicker1.SelectedDate.Value : DateTime.Today;
                dtend = datePicker2.SelectedDate.HasValue ? datePicker2.SelectedDate.Value : DateTime.Today;
                dtend = dtend.Date.AddDays(1);
                var ob = from o in rl.VokzalTable where o.datedoc >= dtbeg && o.datedoc < dtend select o;
                foreach (var it in ob)
                {
                    if (it.Routes.RouteType.insurance == true)
                    {
                        it.sum_insurance =(float)( it.qnt_tickets * 1.5);
                    }
                    else
                    {
                        it.sum_insurance = 0;
                    }
                }
                rl.SaveChanges();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
